//
//  KKEmployeePerformanceDetailView.m
//  Butler
//
//  Created by liaozhenming on 16/6/22.
//  Copyright © 2016年 liaozhenming. All rights reserved.
//

#import "KKEmployeePerformanceDetailView.h"

#import "EmployeePerformanceDetailTableViewCell.h"

@implementation KKEmployeePerformanceDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame: frame];
    if (self) {
        
        UIView *contentView = [self contentView];
        contentView.backgroundColor = [UIColor kk_colorWithHexString: @"f0f0f0"];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, CGRectGetWidth(contentView.bounds), 44)];
        titleLabel.backgroundColor = [UIColor kk_colorWithHexString: @"71d47c"];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.text = @"服务员业绩详情";
        [contentView addSubview: titleLabel];
        
        {
            UITableView *tableView = [[UITableView alloc] initWithFrame: CGRectMake(10, 44, CGRectGetWidth(contentView.bounds) - 20, CGRectGetHeight(contentView.bounds) - 154)];
            tableView.dataSource = self;
            tableView.delegate = self;
            tableView.rowHeight = 60.0f;
            [contentView addSubview: tableView];
            self.tableView = tableView;
        }
        {
            UIView *footerView = [[UIView alloc] initWithFrame: CGRectMake(10, CGRectGetMaxY(self.tableView.frame), CGRectGetWidth(contentView.bounds) - 20, 60)];
            [footerView kk_cornerRadius: 3.0];
            [footerView setBackgroundColor: [UIColor whiteColor]];
            [contentView addSubview: footerView];
            _employeeNumberLabel = [[UILabel alloc] initWithFrame: CGRectMake(20, 20, 100, 20)];
            _employeeNumberLabel.backgroundColor = [UIColor clearColor];
            _employeeNumberLabel.text = @"工号:";
            _employeeNumberLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [footerView addSubview: _employeeNumberLabel];
            
            _employeeNameLabel = [[UILabel alloc] initWithFrame: CGRectMake(180, 20, 100, 20)];
            _employeeNameLabel.backgroundColor = [UIColor clearColor];
            _employeeNameLabel.text = @"姓名:";
            _employeeNameLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [footerView addSubview: _employeeNameLabel];
            
            _employeePerformanceLabel = [[UILabel alloc] initWithFrame: CGRectMake(320, 20, 100, 20)];
            _employeePerformanceLabel.backgroundColor = [UIColor clearColor];
            _employeePerformanceLabel.text = @"总业绩:";
            _employeePerformanceLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [footerView addSubview: _employeePerformanceLabel];
            
            _employeeCommissionLabel = [[UILabel alloc] initWithFrame: CGRectMake(480, 20, 100, 20)];
            _employeeCommissionLabel.backgroundColor = [UIColor clearColor];
            _employeeCommissionLabel.text = @"总提成:";
            _employeeCommissionLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [footerView addSubview: _employeeCommissionLabel];
        }
        
        UIButton *cancelButton = [UIButton buttonWithType: UIButtonTypeSystem];
        cancelButton.frame = CGRectMake(30, CGRectGetHeight(contentView.bounds) - 50, 120, 34);
        cancelButton.backgroundColor = [UIColor kk_colorWithHexString: @"71d47c"];
        [cancelButton setTitle: @"取消" forState: UIControlStateNormal];
        [cancelButton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
        [cancelButton addTarget: self action: @selector(action_cancel:) forControlEvents: UIControlEventTouchUpInside];
        [cancelButton kk_cornerRadius: 3.0];
        [contentView addSubview: cancelButton];
        
        UIButton *sureButton = [UIButton buttonWithType: UIButtonTypeSystem];
        sureButton.frame = CGRectMake(CGRectGetWidth(contentView.bounds) - 150, CGRectGetHeight(contentView.bounds) - 50, 120, 34);
        sureButton.backgroundColor = [UIColor kk_colorWithHexString: @"71d47c"];
        [sureButton setTitle: @"确定" forState: UIControlStateNormal];
        [sureButton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
        [sureButton addTarget: self action: @selector(action_save:) forControlEvents: UIControlEventTouchUpInside];
        [sureButton kk_cornerRadius: 3.0];
        [contentView addSubview: sureButton];
    }
    return self;
}

#pragma mark - Action methods

- (void)action_cancel:(UIButton*)item {
    
    [self kk_close];
}

- (void)action_save:(UIButton*)item {
    
    [self kk_close];
}

#pragma mark - UITableView methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 5.0f;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    EmployeePerformanceDetailTableViewCell *cell = [EmployeePerformanceDetailTableViewCell kk_cellWithTableView: tableView];
    return cell;
}

@end
